const app = getApp()
Page({
    data: {
        xPageReady: true,
        xUserInfo: '',
        navigation: [
            {
                path: '/subuser/pages/mine/dayremb/index?type=riji',
                title: '我的日记',
                icon:"icon-riji font-28",
                show:true
            },
            {
                path: '/subuser/pages/mine/dayremb/index?type=pain',
                title: '疼痛日记',
                icon:"icon-tengtongriji font-28",
                show:true
            },
            {
                path: '/subtool/pages/community/mytiegroup/index',
                title: '我的帖子',
                icon:"icon-remenhuati font-28 ",
                show:true
            },
            {
              path: '/subuser/pages/mine/feel/index',
              title: '练习感受',
              icon:"icon-lianxi font-28",
              show:true
            }
        ],
        target_content:'',
        showModel:true
    },
    onShareAppMessage: function () {
      return {
        title: '疼痛久治不愈？还有一招',
        path:'/pages/navigation/index/index',
        imageUrl: 'https://7633-v3-92ah4-1300208657.tcb.qcloud.la/static/share_all.jpg',
      };
    },
    onLoad: function () {
        let that = this
        app.watch(this, {
            xUserInfo: function (val) {
                if (val != '')
                that.setData({
                    xPageReady: false
                })
            }
        })
        
        that.xInfo()
    },
    onShow: function () {
      let that =this
      if(app.globalData.user_refresh){
        that.xInfo()
      }
      try {
        var value = wx.getStorageSync('moreMain')
        if (value) {
          this.setData({
            showModel:false
          })
        }
      } catch (e) {
        
      }
    },
    // 联系客服
    xMessage:function(){
      var url= 'https://7633-v3-92ah4-1300208657.tcb.qcloud.la/static/cell.png?time='+Date.now() //地址加上时间戳，否则从缓存中加载
      wx.previewImage({
        urls: [url],
      })
    },
    xInfo: async function () {
        let that = this
        // that.setData({
        //   xUserInfo:''
        // })
        // 站内消息
        // await wx.cloud.callFunction({
        //   name: 'station_message',
        //   data: {
        //     action: "get_unread_message_count"
        //   }
        // }).then(res => {
        //     that.setData({
        //       xMail:res.result
        //     })
        // })

        // 用户信息
        await wx.cloud.callFunction({
            name: 'user',
            data: {
                action: 'detail'
            }
        }).then(res => {
            let user = res.result
            that.setData({
               xUserInfo: user
            })
        })
        that.setData({
          xPageReady: false
        })
    },
    // 用户目标
    getTarget(){
        let that=this;
        wx.cloud.callFunction({
          name: 'user',
          data: {
              action: "get_user_target"
          }
        }).then(res => {
          that.setData({
            target_content:res.result.target_content
          })
        })
    },
    // 注册
    xRegister: function (e) {
        let that = this;
        // let path = '/pages/navigation/user/index'
        // wx.navigateTo({
        //   url: '/pages/navigation/login/index?path='+path+'&ready',
        // })
        wx.navigateTo({
          url: '/subuser/pages/personal_information/index',
        })
    },
    xHide:function(){
      this.setData({
        showModel:false
      })
      this.setData({
        showModel:true
      })
    },
    // 获取当前系统信息
    // xGetSystem(){
    //   let that = this
    //   that.setData({
    //     showModel:true
    //   })
    //   wx.getSystemInfo({
    //     success (res) {
    //       that.setData({
    //         system:res.system.match('Android') ? 'Android': 'IOS'
    //       })
    //       if(that.data.system=='IOS'){
    //         wx.setClipboardData({
    //           data: 'https://muheal.cn/DesktopShortcut',
    //           success (res) {
    //             wx.showToast({
    //               title: '已复制链接,在浏览器中打开',
    //               icon:'none'
    //             })
    //           }
    //         })
    //       }
    //     }
    //   })
    // },
    // 工作台
    xToFile: function (e) {
      let path = e.currentTarget.dataset.path
      let id = this.data.xUserInfo.user_id
      wx.navigateTo({
          url: path ,
      })
    },
    // 消息
    xToNews: function () {
      wx.navigateTo({
          url: '/subsale/pages/news/index/index',
      })
    },
    
    xToMail: function () {
        wx.navigateTo({
            url: '/subsale/pages/email/list/index',
        })
    },  
    // 用户目标
    xToTarget:function(e){
       wx.navigateTo({
          url: '/subsale/pages/product/target/index?type=1',
       })
    }
})